/*
 * @Author: WangLi
 * @Date: 2024-03-11 22:14:38
 * @LastEditors: WangLi
 * @LastEditTime: 2024-04-11 16:06:35
 */
import { canIUseModel } from "../../../utils/version";

Component({
  externalClasses: ["custom-class"],
  options: {
    multipleSlots: true,
    addGlobalClass: true,
  },
  properties: {
    value: {
      type: String,
      observer: "updateValue",
    },
    type: {
      type: String,
      value: "text",
    },
  },
  data: {
    sliderValue: 0,
  },
  methods: {
    onChange(e) {
      this.setData({
        sliderValue: e.detail.value,
      });
      this.emitChange(e.detail.value);
    },
    emitChange(value) {
      this.triggerEvent("input", value);
      this.triggerEvent("change", value);

      if (canIUseModel()) {
        this.setData({ value });
      }
    },
    updateValue(value, old) {
      if (value === old) {
        return;
      }
      this.setData({ sliderValue: value });
    },
  },
});
